package com.ruoyi.develop.factory.factoryProduceSale.service.impl;

import java.util.List;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.common.utils.DateUtils;
        import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.common.utils.uuid.IdUtils;
import javax.annotation.Resource;
import org.springframework.stereotype.Service;
import com.ruoyi.develop.factory.factoryProduceSale.mapper.FactoryProduceSaleMapper;
import com.ruoyi.develop.factory.factoryProduceSale.domain.FactoryProduceSale;
import com.ruoyi.develop.factory.factoryProduceSale.service.IFactoryProduceSaleService;

/**
 * 生产订单和产品关联Service业务层处理
 * @author lmm
 * @date 2025-05-08
 */
@Service
public class FactoryProduceSaleServiceImpl implements IFactoryProduceSaleService {
    @Resource
    private FactoryProduceSaleMapper factoryProduceSaleMapper;

    /**
     * 查询生产订单和产品关联
     * @param id 生产订单和产品关联主键
     * @return 生产订单和产品关联
     */
    @Override
    public FactoryProduceSale selectById(String id) {
        return factoryProduceSaleMapper.selectById(id);
    }

    /**
     * 查询生产订单和产品关联列表
     * @param entity 生产订单和产品关联
     * @return 生产订单和产品关联
     */
    @Override
    public List<FactoryProduceSale> selectList(FactoryProduceSale entity) {
        return factoryProduceSaleMapper.selectList(entity);
    }

    @Override
    public List<FactoryProduceSale> selectListGroupGoodsId(String produceId) {
        return factoryProduceSaleMapper.selectListGroupGoodsId(produceId);
    }
    /**
     * 新增生产订单和产品关联
     * @param entity 生产订单和产品关联
     * @return 结果
     */
    @Override
    public int insert(FactoryProduceSale entity) {
        if(StringUtils.isBlank(entity.getId())){
            entity.setId(IdUtils.fastSimpleUUID());
        }
                entity.setCreateBy(SecurityUtils.getUsername());
                entity.setCreateTime(DateUtils.getNowDate());
            return factoryProduceSaleMapper.insert(entity);
    }
    @Override
    public int updateByGoodsId(String produceId,String goodsId,String parentId) {
        return factoryProduceSaleMapper.updateByGoodsId(produceId, goodsId, parentId);
    }
    /**
     * 修改生产订单和产品关联
     * @param entity 生产订单和产品关联
     * @return 结果
     */
    @Override
    public int update(FactoryProduceSale entity) {
                entity.setUpdateBy(SecurityUtils.getUsername());
                entity.setUpdateTime(DateUtils.getNowDate());
        return factoryProduceSaleMapper.update(entity);
    }

    @Override
    public int updateStatusByParentId(String status,String parentId) {
        return factoryProduceSaleMapper.updateStatusByParentId(status,parentId);
    }

    /**
     * 批量删除生产订单和产品关联
     * @param ids 需要删除的生产订单和产品关联主键
     * @return 结果
     */
    @Override
    public int deleteByIds(String[] ids) {
        return factoryProduceSaleMapper.deleteByIds(ids);
    }

    /**
     * 删除生产订单和产品关联信息
     * @param id 生产订单和产品关联主键
     * @return 结果
     */
    @Override
    public int deleteById(String id) {
        return factoryProduceSaleMapper.deleteById(id);
    }
    @Override
    public List<FactoryProduceSale> selectByParentId(String parentId) {
        return factoryProduceSaleMapper.selectByParentId(parentId);
    }

}
